<template>
  <div>加入代码{{count/numberval/1107568*100}}

    <div>
      {{allarr }}
    </div>
  </div>

</template>
<script setup>
import { ref, reactive } from "vue";
// //
// const one = reactive([]);

// const randoArr = reactive([]);

// // 自由组合
// const getCombinations = function (arr, k) {
//   let result = [];
//   const combine = (start, combo) => {
//     if (combo.length === k) {
//       // arrryAddThere.push(combo.join(""));
//       result.push([...combo]);
//       return;
//     }
//     for (let i = start; i < arr.length; i++) {
//       combo.push(arr[i]);
//       combine(i + 1, combo);
//       combo.pop();
//     }
//   };
//   combine(0, []);
//   return result;
// };

//自动抽取
function getRandomSixNumbersFrom1To33(arr) {
  // 创建一个从1到33的数组
  let numbers = Array.from({ length: 33 }, (_, i) => i + 1);
  // arr.splice(index, 1)

  if (arr.length > 1) {
    arr.map((x) => {
      arr.splice(x, 1);
    });
  }

  // 使用Fisher-Yates洗牌算法对数组进行洗牌
  for (let i = numbers.length - 1; i > 0; i--) {
    // 生成一个0到i之间的随机索引
    let j = Math.floor(Math.random() * (i + 1));
    // 交换当前元素和随机索引处的元素
    [numbers[i], numbers[j]] = [numbers[j], numbers[i]];
  }

  // 返回前六个数
  return numbers.slice(0, 6);
}
//推荐的
var zhuangjia = [
  [7, 13, 18, 23, 26, 29],
  [4, 6, 11, 13, 16, 21],
  [2, 10, 15, 17, 25, 27],
];
// 往期
var arr2 = [
  [7, 11, 13, 18, 27, 31],
  [6, 13, 17, 22, 24, 29],
  [4, 6, 7, 16, 17, 21],
  [2, 4, 11, 12, 23, 25],
];
//买的号码
var buy = [
  [4, 6, 7, 13, 16, 21, 27],
  [4, 6, 8, 16, 27, 33],
  [1, 14, 16, 23, 29],
  [2, 5, 8, 9, 17, 20],
  [2, 16, 25, 29, 30, 32],
  [13, 14, 17, 19, 20, 25],
  [2, 9, 21, 15, 15, 25],
  [6, 8, 10, 16, 20, 29],
  [6, 9, 11, 14, 18, 28],
  [6, 7, 8, 9, 10, 11],
  [6, 9, 13, 18, 21, 27],
  [2, 8, 10, 12, 17, 20],
  [6, 8, 9, 11, 14, 18],
  [2, 9, 14, 16, 20, 21],
  [6, 9, 11, 13, 18, 28],
];

// 排除
var arr4 = [
  [4, 13, 28],
  [6, 11, 32],
];
var arr5 = [];
const count = ref(0);
const numberval = ref(1000);
var commonCount = 0;

var allarr = reactive([]);
function all() {
  var condition = true;
  var arr1 = [];
  commonCount = 0;

  while (condition) {
    // 循环体代码
    count.value = count.value + 1;

    arr1 = getRandomSixNumbersFrom1To33([]).sort((a, b) => a - b); //自动组合数组

    //相同不能
    if (whitefun(arr1, arr2, 3)) {
      condition = true;
    }
    if (whitefun(arr1, arr2, 2)) {
      condition = true;
    } else if (arr1.every((element) => element > 16)) {
      condition = true;
    } else if (arr1.every((element) => element < 16)) {
      condition = true;
    } else if (arr1.every((element) => element % 2 === 0)) {
      condition = true;
    } else if (arr1.every((element) => element % 2 !== 0)) {
      condition = true;
    } else if (whitefun(arr1, new Set(allarr), 2)) {
      condition = true;
    } else if (whitefun(arr1, buy, 2)) {
      condition = true;
    } else if (whitefun(arr1, arr4, 1)) {
      condition = true;
    } else if (whitefun(arr1, zhuangjia, 2)) {
      condition = true;
    } else if (whitefun(arr1, arr5, 2)) {
      condition = true;
    } else if (hasThreeConsecutiveArithmetic(arr1)) {
      condition = true;
    } else if (forfun(arr1, arr2, 1)) {
      condition = true;
    } else {
      if (allarr.length <= 4) {
        allarr.push(arr1);
      }

      condition = false;
    }
  }

  // console.log("idedede", i, arr1);
}

async function processArraySync() {
  let i = 0;
  while (i < numberval.value) {
    all();
    // 执行同步操作
    i++;
  }
}

processArraySync();

function hasThreeConsecutiveArithmetic(arr) {
  // 检查数组长度是否至少为3
  if (arr.length < 3) {
    return false;
  }

  // 遍历数组，检查每三个连续的数字
  for (let i = 0; i < arr.length - 2; i++) {
    const a = arr[i];
    const b = arr[i + 1];
    const c = arr[i + 2];

    // 检查是否满足等差数列的条件
    if (b - a === c - b) {
      return true;
    }
  }

  return false;
}

function whitefun(list1, list2 = [], numbershu = 2) {
  let val = false;

  if (list2.length == 0) {
    return val;
  }
  let list11 = new Set(list1);
  let j = 0;
  while (j < list2.length) {
    // 循环体代码
    commonCount = list2[j].filter((value) => list11.has(value)).length;
    if (commonCount >= numbershu) {
      val = true;
      break;
    }
    j++;
  }
  return val;
}

function forfun(list1, list2 = [], numbershu = 1) {
  let val = true;

  if (list2.lengt == 0) {
    return val;
  }
  let list11 = new Set(list1);
  let j = 0;
  while (j < list2.length) {
    // 循环体代码
    commonCount = list2[j].filter((value) => list11.has(value)).length;
    if (commonCount >= numbershu) {
      val = false;
    }
    j++;
  }
  return val;
}
//

// console.log(one, randoArr, getCombinations(randoArr));
</script>
